package com.aspire.query.util;


import com.aspire.query.config.ConfigDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author zhouyumin
 */
@Configuration
public class MyConnection {

    @Autowired
    private ConfigDO configDo;

    @Bean
    public Connection getConnection() {
        Connection connection = null;
        try {
            Class.forName(configDo.getDriverClassName());
            connection = DriverManager.getConnection(configDo.getUrl(), configDo.getUsername(), configDo.getPassword());
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }

}
